package com.haotunet.app.goldtreasure.utils;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.telephony.TelephonyManager;

import com.umeng.message.UmengRegistrar;

public class Config {
    /*获取手机imei号*/
    public static String getImei(Context context) {
        TelephonyManager mTelephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        return mTelephonyMgr.getDeviceId();
    }

    /*获取友盟推送Token*/
    public static String getUmengToken(Context context) {
        return UmengRegistrar.getRegistrationId(context);
    }

    /*获取版本名*/
    public static String getVersionName(Context context) {
        PackageManager manager = context.getPackageManager();
        PackageInfo info;
        String versionName = null;
        try {
            info = manager.getPackageInfo(context.getPackageName(), 0);
            versionName = info.versionName;
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
        return versionName;
    }

    /*获取版本号*/
    public static int getVersionCode(Context context) {
        PackageManager manager = context.getPackageManager();
        PackageInfo info;
        int versionCode = 0;
        try {
            info = manager.getPackageInfo(context.getPackageName(), 0);
            versionCode = info.versionCode;
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
        return versionCode;
    }

    /*获取Manifest中metaData里的值*/
    public static String getStringMetaData(Context context, String key) {
        Object r = null;
        try {
            PackageManager manager = context.getPackageManager();
            ApplicationInfo info = manager.getApplicationInfo(
                    context.getPackageName(), PackageManager.GET_META_DATA);
            if (info != null) {
                r = info.metaData.get(key);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return r == null ? "" : r.toString();
    }


}
